package com.googlecode.groovy_toy_orm

import com.googlecode.groovy_toy_orm.internal.BitMaskState
import com.googlecode.groovy_toy_orm.internal.CodeBased
import org.testng.annotations.Test

/**
 * @author: DavydovMD
 * Date: 16.04.13
 * Time: 15:50
 */
class BitMaskStateTest {
   static  enum CurrencyStateBits implements CodeBased {
        CURRENCY(1),
        USD(2),
        TOMMOROW(4),
        TODAY(8)

        final int code;

        private  CurrencyStateBits(int code) {
            this.code = code;
        }
    }

    @Test
    public void test(){
        BitMaskState<CurrencyStateBits> state = BitMaskState.fromCode(CurrencyStateBits.class, 5)
        assert state.is(CurrencyStateBits.CURRENCY)
        assert state.is(CurrencyStateBits.TOMMOROW)
        assert !state.is(CurrencyStateBits.TODAY)
        assert state.getStates() == [CurrencyStateBits.CURRENCY, CurrencyStateBits.TOMMOROW]
    }
}
